﻿
$("#heightexpno").click(function(){
    $("#heightexpdiv").toggle(200);
});
//铺路推荐
var tjcurrentIndex=1;
var jycurrentIndex=1;
var zhncurrentIndex=1;
var quecurrentIndex=1;

var tjover=0;//推荐接口数据状态 0有数据 1没数据
var jyover=0;//经验接口数据状态
var zhnover=0;//召唤你接口数据状态
var queover=0;//召唤你接口数据状态
var pageSize=10;//一页显示几条新闻
//var newsnum=0;//第几条新闻
var readyover=0;//控制页面滚动0正常 1加载中

//时间 几天前 几分钟前
function getDateTimeStamp(dateStr){
    dateStr=dateStr.match(/[0-9\-T\:]+/)[0].replace(/T/g,' ');
    return Date.parse(dateStr.replace(/-/gi,"/"));
}
function getDateDiff(dateTimeStamp){
    var minute = 1000 * 60;
    var hour = minute * 60;
    var day = hour * 24;
    var halfamonth = day * 15;
    var month = day * 30;
    var now = new Date().getTime();
    var diffValue = now - dateTimeStamp;
    if(diffValue < 0){ result="刚刚";return;}
    var monthC =diffValue/month;
    var weekC =diffValue/(7*day);
    var dayC =diffValue/day;
    var hourC =diffValue/hour;
    var minC =diffValue/minute;
    if(monthC>=1){
        result="" + parseInt(monthC) + "月前";
    }
    else if(weekC>=1){
        result="" + parseInt(weekC) + "周前";
    }
    else if(dayC>=1){
        result=""+ parseInt(dayC) +"天前";
    }
    else if(hourC>=1){
        result=""+ parseInt(hourC) +"小时前";
    }
    else if(minC>=1){
        result=""+ parseInt(minC) +"分钟前";
    }else
        result="刚刚";
    return result;
}

document.onkeydown=function(event){
    var e = event || window.event || arguments.callee.caller.arguments[0];
    if(e && e.keyCode==13){ // enter 键
        var word=document.getElementById("searchinput").value;
        if(word){
            if(word.match(/^\s+$/g)){
                console.log("没有填信息")
            }else{
                location.href="searchdetail.html?searchKey="+word;
            }
        }
    }
};

//召唤你页面  //按钮
var expbtn=document.getElementById("expbtn");  //经验
var askyou=document.getElementById("askyou");   //召唤你

var explist=document.getElementById("explist");//经验
var askyoulist=document.getElementById("askyoulist");//召唤你
var quelist=document.getElementById("quelist"); //问题
var loca=location.href;

askyou.onclick=function(){
    $.cookie("pulupagescroll","");//当前滚动距离
    $.cookie("pulupagepage","");//当前显示页面
    $.cookie("tjcurrentIndex","");//推荐数据页码
    $.cookie("zhncurrentIndex","");//召唤你数据页码
    $.cookie("jycurrentIndex","");//经验 铺路数据页码
    $.cookie("quecurrentIndex","");//问题 铺路数据页码
    location.href="questionlistzhn.html";
};
expbtn.onclick=function(){
    $.cookie("pulupagescroll","");//当前滚动距离
    $.cookie("pulupagepage","");//当前显示页面
    $.cookie("tjcurrentIndex","");//推荐数据页码
    $.cookie("zhncurrentIndex","");//召唤你数据页码
    $.cookie("jycurrentIndex","");//经验 铺路数据页码
    $.cookie("quecurrentIndex","");//问题 铺路数据页码
    location.href="questionlistjy.html";
};

//付费分享
var sharepay=document.getElementsByClassName("sharepay");
var sharepaymob=document.getElementsByClassName("sharepaymob")[0];

var sharepayword=document.getElementsByClassName("sharepayword")[0];
var askpayword=document.getElementsByClassName("askpayword")[0];
var modalbg=document.getElementsByClassName("modal_bg2")[0];
for(var sh=0;sh<sharepay.length;sh++){
    sharepay[sh].onclick=function(){
        modalbg.style.display="block";
        sharepaymob.style.display="block";
        sharepayword.style.display="block";
        askpayword.style.display="none";
    }
}

function changeclass3(){
    modalbg.className='modal_bg modal_bg';
    sharepaymob.className='action_menu_container sharepaymob';
    clearTimeout();
    timer2=null;
    changedisplay3();
};
function changedisplay3(){
    modalbg.style.display="none";
    sharepaymob.style.display="none";
};

var id;
if($.cookie("MYID")){id=$.cookie("MYID")};
console.log(id);
var returnurl=encodeURIComponent("https://www.pulu.com/weixin/questionlistjy.html"); //同意后跳转页面

//所有页面方法url:ydqmyexpurl+id+"&currentIndex="+jycurrentIndex+"&pageSize="+pageSize+isheigh,
function allftn(){
    //经验数据
    $().ready(function(){
        if($.cookie("pulupagepage")){
            $("#explist div.addlistplace div").remove();
            var pagelist=document.getElementsByClassName("HomeMainFeed");
            var navlist=document.getElementsByClassName("HeaderSwitcherItem");
            readyover=1;//控制页面滚动
            //经验
            if($.cookie("jycurrentIndex")!=="NaN"){
                jypageSize=parseFloat($.cookie("jycurrentIndex"))*10;
            }else{
                jypageSize=10;
            }
            jy(ydqmyexpurl,1,jypageSize,"");
            jycurrentIndex=parseFloat($.cookie("jycurrentIndex"));
        }
        else{
            if(id){
                jy(ydqmyexpurl,jycurrentIndex,pageSize,"");
            }
        }
    });
    var upanddown=127;
    $(window).scroll(function(){
        $(".quicklist").css("display","none");
        $("#refreshbtn").css("display","block");
        var mainheight=$(".home_feed").height();
        var windowheight=$(window).height();
        var what=$(".home_feed").offset().top;
        var chajuli=$(".home_feed").offset().top - $(window).scrollTop();
        var cz=windowheight-mainheight+50;
        if(chajuli<cz&&readyover===0){
            if(jyover==0){
                jycurrentIndex++;
                readyover=1;
                jy(ydqmyexpurl,jycurrentIndex,pageSize,"");
            }
        }
        //导航条隐藏显示
        //var a2=chajuli;
        //if(a2<upanddown){
        //    upanddown=a2;
        //    //向下滚动
        //    if(chajuli<36){
        //        $(".fixed_header").css({"position":"fixed","top":"-44px"});
        //        $(".wrapper.home_feed").css({"margin-top":"44px"});
        //        $("#page_wrapper").css("margin-top","44px");
        //    }
        //}
        //else{
        //    upanddown=a2;
        //    //向上滚动
        //    if(0<chajuli){
        //        $(".fixed_header").css({"position":"absolute","top":"0px"});
        //        $(".wrapper.home_feed").css({"margin-top":"0"});
        //        $("#page_wrapper").css("margin-top","83px");
        //    }
        //}
    });
    //刷新页面
    $("#refreshbtn").click(function(){
        jycurrentIndex=1;
        $("#waiting1").css("display","block");
        $("#nonews1").css("display","none");
        $(".fixed_header").css({"position":"absolute","top":"0px"});
        $(".wrapper.home_feed").css({"margin-top":"0"});
        $("#page_wrapper").css("margin-top","127px");
        $("#explist .addlistplace div").remove();
        jy(ydqmyexpurl,jycurrentIndex,pageSize,"");
    });
}
$(document).ready(function(){
    if(is_weixn()){
        if($.cookie("wxopenid")){
            //=======================================================
            //从登录页返回有openid没有id
            if($.cookie("MYID")){
                allftn();
            }
            else{
                location.href="login.html";
            }
            //=======================================================
        }
        else{
            //先微信验证获取openid 如果已经授权过了 直接页面截取openid 然后发送请求获取 用户的ID
            var reg=new RegExp("code=[a-zA-Z0-9]*");
            if(window.location.href.match(reg)){
                var code=window.location.href.match(reg);
                $.ajax({
                    type:"GET",
                    url:"GetOpenId.ashx?"+code,
                    async: false,
                    success:function(data){
                        var dat=data;
                        $.cookie("wxod",dat);
                        //发请求获取用户的id
                        $.ajax({
                            type:"GET",
                            url:getwxopenidurl+dat,
                            success:function(d){
                                //如果没有用户id 则证明用户是第一次登陆 保存openid跳转至登录页面
                                if(!d.Data){
                                    $.cookie("wxopenid",dat);
                                    //alert($.cookie("wxopenid"));
                                    location.href="login.html";
                                }else if(d.Data&&d.Data.userId){
                                    $.cookie("wxopenid",d.Data.openId);
                                    $.cookie("MYID",d.Data.userId);
                                    id=d.Data.userId;
//=======================================================================
                                    allftn();
//=======================================================================
                                }
                                //如果有用户ID 就把cookies里的用户id替换成获取到的id  在这里控制跳转提示框
                            }
                        })
                    }
                })
            }else{
                location.href="https://open.weixin.qq.com/connect/oauth2/authorize?appid=wx658c34793ecfd9f9&redirect_uri="+returnurl+"&response_type=code&scope=snsapi_base&state=STATE#wechat_redirect";
            }
        }
    }
    else{
        allftn();
    }
})